import { reactive } from 'vue'
import type { FormRules } from 'element-plus'
const validateNumber = (rule: any, value: any, callback: any) => {
    if (isNaN(value)) {
        callback(new Error('表单输入内容应为数字'));
    } else {
        callback();
    }
};
export interface RuleForm {
    name: string
    region: string
    date1: string
    date2: string
    delivery: boolean
    type: string[]
    resource: string
    desc: string
    number: null
}
export const rules = reactive<FormRules<any>>({
    name: [
        { required: true, message: '请输入表单内容', trigger: 'blur' },
        { min: 3, max: 5, message: '请输入3-5个文字', trigger: 'blur' },
    ],
    region: [
        {
            required: true,
            message: '请选择下拉选项',
            trigger: 'change',
        },
    ],
    date1: [
        {
            type: 'date',
            required: true,
            message: '请选择日期',
            trigger: 'change',
        },
    ],
    date2: [
        {
            type: 'date',
            required: true,
            message: '请选择时间',
            trigger: 'change',
        },
    ],
    type: [
        {
            type: 'array',
            required: true,
            message: '请选择至少一种选项',
            trigger: 'change',
        },
    ],
    resource: [
        {
            required: true,
            message: '请选择选项',
            trigger: 'change',
        },
    ],
    desc: [
        { required: true, message: '请输入表单内容', trigger: 'blur' },
    ],
    number: [
        { required: true, message: '请输入表单内容', trigger: 'blur' },
        { validator: validateNumber, trigger: 'blur' }],
})

